package com.yupi.yuaicodemother.ai.save;

import com.yupi.yuaicodemother.ai.model.AIProcessCode;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;

@Service
public class SQLSaveTool {
    private final String baseDir = "src/main/resources/processCode/" + LocalDate.now();

    public void save(AIProcessCode result) throws IOException {
        Path root = Paths.get(baseDir);
        Files.createDirectories(root);

        Files.writeString(root.resolve("sql.sql"),          result.getSqlCode(),         StandardCharsets.UTF_8);


    }
}
